package com.xinkao.example.util;

import org.springframework.stereotype.Component;

import java.io.File;

/**
 * @author zhoujing
 * @date 2021/3/19 8:47
 * @description
 */
@Component
public class DocUtils {

    /**
     * 不带文件名的Path：如：D:\xml2\2018\04\
     * @param filePath
     */
    public static void isExist2(String filePath) {
        String[] paths = filePath.split("\\\\");
        String dir = paths[0].trim();


        //注意此处循环的长度
        for (int i = 0; i < paths.length - 1; i++) {
            try {
                StringBuffer str = new StringBuffer();
                dir = str.append(dir).append("/").append(paths[i + 1].trim()).toString();
                File dirFile = new File(dir);
                if (!dirFile.exists()) {
                    dirFile.mkdir();
                }
            } catch (Exception err) {
                System.err.println("文件夹创建发生异常");
            }
        }
    }
}
